package cn.iocoder.yudao.module.famous.doctor.controller.admin.banner;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.famous.doctor.controller.admin.banner.vo.*;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.banner.FamBannerDO;
import cn.iocoder.yudao.module.famous.doctor.convert.banner.FamBannerConvert;
import cn.iocoder.yudao.module.famous.doctor.service.banner.FamBannerService;

@Tag(name = "管理后台 - 名医-轮播图")
@RestController
@RequestMapping("/famous.doctor/fam-banner")
@Validated
public class FamBannerController {

    @Resource
    private FamBannerService famBannerService;

    @PostMapping("/create")
    @Operation(summary = "创建名医-轮播图")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-banner:create')")
    public CommonResult<Long> createFamBanner(@Valid @RequestBody FamBannerCreateReqVO createReqVO) {
        return success(famBannerService.createFamBanner(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新名医-轮播图")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-banner:update')")
    public CommonResult<Boolean> updateFamBanner(@Valid @RequestBody FamBannerUpdateReqVO updateReqVO) {
        famBannerService.updateFamBanner(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除名医-轮播图")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-banner:delete')")
    public CommonResult<Boolean> deleteFamBanner(@RequestParam("id") Long id) {
        famBannerService.deleteFamBanner(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得名医-轮播图")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-banner:query')")
    public CommonResult<FamBannerRespVO> getFamBanner(@RequestParam("id") Long id) {
        FamBannerDO famBanner = famBannerService.getFamBanner(id);
        return success(FamBannerConvert.INSTANCE.convert(famBanner));
    }

    @GetMapping("/list")
    @Operation(summary = "获得名医-轮播图列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-banner:query')")
    public CommonResult<List<FamBannerRespVO>> getFamBannerList(@RequestParam("ids") Collection<Long> ids) {
        List<FamBannerDO> list = famBannerService.getFamBannerList(ids);
        return success(FamBannerConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得名医-轮播图分页")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-banner:query')")
    public CommonResult<PageResult<FamBannerRespVO>> getFamBannerPage(@Valid FamBannerPageReqVO pageVO) {
        PageResult<FamBannerDO> pageResult = famBannerService.getFamBannerPage(pageVO);
        return success(FamBannerConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出名医-轮播图 Excel")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-banner:export')")
    @OperateLog(type = EXPORT)
    public void exportFamBannerExcel(@Valid FamBannerExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<FamBannerDO> list = famBannerService.getFamBannerList(exportReqVO);
        // 导出 Excel
        List<FamBannerExcelVO> datas = FamBannerConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "名医-轮播图.xls", "数据", FamBannerExcelVO.class, datas);
    }

}
